<template>
  <div>
    <el-form :model="form" label-width="auto" style="max-width: 600px" ref="ruleFormRef">
      <el-form-item label="项目名称" prop="projectName">
        <el-input v-model="form.projectName" placeholder="请输入项目名称" />
      </el-form-item>
      <el-form-item label="选择分支" prop="branchName">
        <el-input v-model="form.branchName" placeholder="请输入分支名称" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit(ruleFormRef)">提交</el-button>
        <el-button @click="onReset(ruleFormRef)">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue';
import { getTestApi, submitDeployApi } from '@/api/deploy';

const ruleFormRef = ref();

const form = reactive({
  projectName: '',
  branchName: '',
});

const onSubmit = async (formEl) => {
  if (!formEl) return;
  formEl.validate((valid, fields) => {
    if (valid) {
      handleRequest();
    } else {
      console.log('error submit!');
      return false;
    }
  });
};
const onReset = (formEl) => {
  if (!formEl) return;
  formEl.resetFields()
};

// 请求接口
const handleRequest = async () => {
  const res = await submitDeployApi(form);
  console.log(res, 'res');
}
</script>